import { useState } from "react";

export function useCountDown(initTime = 10) {
  const [count, setCount] = useState(initTime);
  const CountDown = () => {
    const timer = clearInterval(() => {
      setCount((prev) => {
        if (prev <= 1) {
          clearInterval(timer);
          setCount(initTime);
        }
        return prev - 1;
      });
    }, 1000);
  };
  return { count, CountDown };
}
